package main

import (
	"fmt"
	"os"
	"strconv"

	"./weightconv"
)

func WeightPrint(t float64) { // 输出重量转换提示
	p := weightconv.Pound(t)
	kg := weightconv.Kilogram(t)
	fmt.Printf("%s = %s, %s = %s\n",
		p, weightconv.PToKG(p), kg, weightconv.KGToP(kg))
}

func main() {
	var t float64
	if len(os.Args) <= 1 { // 命令行没有参数，从标准输入读取参数
		fmt.Print("Please enter weight value: ")
		fmt.Scanf("%f", &t)
		WeightPrint(t)
	} else { // 读取命令行参数
		for _, arg := range os.Args[1:] {
			t, err := strconv.ParseFloat(arg, 64)
			if err != nil {
				fmt.Fprintf(os.Stderr, "cf: %v\n", err)
				os.Exit(1)
			}
			WeightPrint(t)
		}
	}
}
